<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="automovelForm">

        <rich:panel>
            <f:facet name="header">Cadastrar Frota</f:facet>
			
			<h:panelGrid columns="1">
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Marca:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.marca}" 
						maxlength="50"
						required="true"
						size="70"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Modelo:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.modelo}" 
						maxlength="50"
						required="true"
						size="70"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Cor:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.cor}" 
						maxlength="20"
						required="true"
						size="40"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Combustível:</ui:define>
					<h:selectOneMenu value="#{cadastrarAutomovel.idCombustivelSelecionado}" required="false">
						<f:selectItems value="#{cadastrarAutomovel.listaCombustiveis}"/>
					</h:selectOneMenu>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Ano de Frabricação:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.anoFabricacao}" 
						maxlength="4"
						required="true"
						size="6"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Ano Modelo:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.anoModelo}" 
						maxlength="4"
						required="true"
						size="6"
						onkeydown="Mascara(this,Integer)"
						onkeyup="Mascara(this,Integer)"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Placa:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.placa}" 
						maxlength="7"
						required="true"
						size="9"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Chassi:</ui:define>
					<h:inputText value="#{cadastrarAutomovel.automovelEdicao.chassi}" 
						maxlength="50"
						required="true"
						size="70"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Tipo:</ui:define>
					<h:selectOneMenu value="#{cadastrarAutomovel.automovelEdicao.tipo}"
						required="true">
						<f:selectItem itemLabel="Selecione" />
						<f:selectItem itemLabel="Automóvel" itemValue="Automóvel"/>
						<f:selectItem itemLabel="Caminhonete" itemValue="Caminhonete"/>
						<f:selectItem itemLabel="Camioneta" itemValue="Camioneta"/>
						<f:selectItem itemLabel="4x4" itemValue="4x4"/>
						<f:selectItem itemLabel="Caminhão" itemValue="Caminhão"/>
						<f:selectItem itemLabel="Moto" itemValue="Moto"/>
					</h:selectOneMenu>
				</s:decorate>
				
			</h:panelGrid>
			
			<rich:dataTable value="#{cadastrarAutomovel.listaValores}"
				var="_valor"
				rows="5"
				onRowMouseOver="this.style.backgroundColor='#6495ED'"
       			onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
				id="tabelaValores">
				
				<f:facet name="header">Tabela de Valores do Veículo</f:facet>
				
				<rich:column>
					<f:facet name="header">Tabela</f:facet>
					<h:outputText value="#{_valor.tabelaValor.dscTabela}" />
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Valor da Diária</f:facet>
					<h:outputText value="#{_valor.valorDiaria}" converter="conversorMonetario"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Valor do Km</f:facet>
					<h:outputText value="#{_valor.valorKm}" converter="conversorMonetario"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header">Valor da Hora</f:facet>
					<h:outputText value="#{_valor.valorHora}" converter="conversorMonetario"/>
				</rich:column>
				
				<rich:column>
					<f:facet name="header"></f:facet>
					<a:commandLink value="Excluir" 
						onclick="javascript:if(!confirm('Tem certeza que deseja excluir? Após clicar em OK não poderá mais ser desfeita a exclusão.'))return false;"
						action="#{cadastrarAutomovel.excluirValor(_valor)}" ajaxSingle="true"
						reRender="tabelaValores"/>
				</rich:column>
			</rich:dataTable>				
			<rich:datascroller for="tabelaValores" renderIfSinglePage="false"/>
        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="novoValor" value="Novo Valor" action="#{cadastrarAutomovel.inicializaPopupNovoValor()}"/>
            <h:commandButton id="salvar" value="Salvar" action="#{cadastrarAutomovel.salvar()}"
            	onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;"/>
            <h:commandButton id="cancel" value="Cancelar" action="#{cadastrarAutomovel.cancelar()}"
            	immediate="true"/>
        </div>

    </h:form>

	<rich:modalPanel id="modalValor" height="250" width="550"
		 showWhenRendered="#{cadastrarAutomovel.exibePopupNovoValor}">
         	<f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Novo Valor"/>
            </h:panelGroup>
        </f:facet>
	       
	    <h:form id="formModalValor">
	    	<h:messages id="messages" globalOnly="true" styleClass="message"
	            errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
	            rendered="#{showGlobalMessages != 'false'}"/>
	    	<h:panelGrid columns="1">
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Tabela</ui:define>
	    			<h:selectOneMenu value="#{cadastrarAutomovel.idTabelaSelecionada}"
	    				required="true">
	    				<f:selectItems value="#{cadastrarAutomovel.listaTabelas}"/>
	    			</h:selectOneMenu>
	    			<h:commandLink action="#{cadastrarAutomovel.inicializaPopupNovaTabela()}"
	    				immediate="true" 
	    				rendered="#{identity.hasRole('CADASTRAR_TABELAS_GRAVAR')}"
	    				value="NOVO" />
	    		</s:decorate>
	    		
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Valor da diária</ui:define>
	    			<h:inputText value="#{cadastrarAutomovel.valorEdicao.valorDiaria}" 
	    				maxlength="10"
	    				required="true"
	    				converter="conversorMonetario"
	    				onkeydown="Mascara(this,Valor)"
	    				onkeyup="Mascara(this,Valor)"/>
	    		</s:decorate>
	    		
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Valor do km</ui:define>
	    			<h:inputText value="#{cadastrarAutomovel.valorEdicao.valorKm}" 
	    				maxlength="10"
	    				required="true"
	    				converter="conversorMonetario"
	    				onkeydown="Mascara(this,Valor)"
	    				onkeyup="Mascara(this,Valor)"/>
	    		</s:decorate>
	    		
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Valor da hora</ui:define>
	    			<h:inputText value="#{cadastrarAutomovel.valorEdicao.valorHora}" 
	    				maxlength="10"
	    				required="true"
	    				converter="conversorMonetario"
	    				onkeydown="Mascara(this,Valor)"
	    				onkeyup="Mascara(this,Valor)"/>
	    		</s:decorate>
	    	</h:panelGrid>
	    	<div align="center">
	    		<h:commandButton action="#{cadastrarAutomovel.adicionarValorAutomovel()}" value="Salvar" />
	    		<h:commandButton action="#{cadastrarAutomovel.cancelarNovoValor()}" value="Cancelar" 
	    			immediate="true"/>
	    	</div>
	    </h:form>
	</rich:modalPanel>
	
	<rich:modalPanel id="modalTabela" height="150" width="400"
		 showWhenRendered="#{cadastrarAutomovel.exibePopupNovaTabela}">
         	<f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Nova Tabela de Valor"/>
            </h:panelGroup>
        </f:facet>
	       
	    <h:form id="formModalTabela">
	    	<h:panelGrid columns="1">
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Descrição</ui:define>
	    			<h:inputText value="#{cadastrarAutomovel.tabelaEdicao.dscTabela}"
	    				required="true" 
	    				maxlength="100"
	    				size="40"/>
	    		</s:decorate>
	    	</h:panelGrid>
	    	<div align="center">
	    		<h:commandButton action="#{cadastrarAutomovel.salvarNovaTabela()}" value="Salvar" />
	    		<h:commandButton action="#{cadastrarAutomovel.cancelarNovaTabela()}" value="Cancelar" 
	    			immediate="true"/>
	    	</div>
	    </h:form>
	</rich:modalPanel>
 </ui:define>
</ui:composition>
